<?php
namespace Admin\Controller;
use Think\Controller;
//猜明星
class GuessStarController extends CommonController {

    public function index(){
        self::user_list();
    }

    //用户模块
    public function user_list()
    {
        //暂时不做分页
        $data['user_list']  =   M('star_member')->select();
        $this->assign("data",$data);
        $this->display('user_list');
    }

    public function user_info()
    {

    }

    public function user_edit()
    {

    }

    //游戏规则
    public function game_rule()
    {
        $data['rule']   =   M('star_money')->find();
        $this->assign("data",$data);
        $this->display('game_rule');
    }

    public function game_rule_edit()
    {
        $where['star_money_id'] =   I('post.star_money_id','','htmlspecialchars');
        $data['sharegroup']     =   I('post.sharegroup','','htmlspecialchars');
        $data['answer']         =   I('post.answer','','htmlspecialchars');
        $data['wrong']          =   I('post.wrong','','htmlspecialchars');
        $data['sharefrend']     =   I('post.sharefrend','','htmlspecialchars');
        $data['resurgence']     =   I('post.resurgence','','htmlspecialchars');
        $data['time']           =   I('post.time','','htmlspecialchars');
        $data['appid']          =   I('post.appid','','htmlspecialchars');

        //安全判断

        $result     =   M('star_money')->where($where)->save($data); // 根据条件更新记录

        //记录相关操作日志

        if (!empty($result)) 
        {
            $msg['state']   =   200;
            $msg['error']   =   '更新成功';
            $this->ajaxReturn ($msg,'JSON');
        }
        else
        {
            $msg['state']   =   -1;
            $msg['error']   =   '更新失败';
            $this->ajaxReturn ($msg,'JSON');
        }
    }

    //更多好玩
    public function game_more()
    {
        $data['game_list']  =   M('star_moreplay')->select();
        $this->assign("data",$data);
        $this->display('game_more');
    }

    public function game_more_add()
    {
        if (IS_AJAX) 
        {
            $data['appid']     =   I('post.appid','','htmlspecialchars');
            $data['url']       =   I('post.url','','htmlspecialchars');
            $data['envVersion']=   I('post.envversion','','htmlspecialchars');
            $data['logo']      =   I('post.logo','','htmlspecialchars');
            $data['content']   =   I('post.content','','htmlspecialchars');
            $data['isshow']    =   I('post.isshow','','htmlspecialchars');
            $data['title']     =   I('post.title','','htmlspecialchars');

            $result     =   M('star_moreplay')->data($data)->add(); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '添加成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '添加失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $this->display('game_more_add');
        }
    }

    public function game_more_edit()
    {
        if (IS_AJAX) 
        {
            $where['star_moreplay_id']  =   I('post.star_moreplay_id','','htmlspecialchars');
            if (empty($where['star_moreplay_id'])) 
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');    
            }

            $data['appid']     =   I('post.appid','','htmlspecialchars');
            $data['url']       =   I('post.url','','htmlspecialchars');
            $data['envVersion']=   I('post.envversion','','htmlspecialchars');
            $data['logo']      =   I('post.logo','','htmlspecialchars');
            $data['content']   =   I('post.content','','htmlspecialchars');
            $data['isshow']    =   I('post.isshow','','htmlspecialchars');
            $data['title']     =   I('post.title','','htmlspecialchars');

            $result     =   M('star_moreplay')->where($where)->save($data); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '更新成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '更新失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $where['star_moreplay_id']  =   I('get.id','','htmlspecialchars');

            if (empty($where['star_moreplay_id'])) 
            {
                $this->error('非法请求');
            }

            $data['game_info']  =   M('star_moreplay')->where($where)->find();

            if ( empty($data)) 
            {
                $this->error('数据不存在');
            }

            $this->assign("data",$data);
            $this->display('game_more_edit');
        }
    }

    //游戏题库
    public function game_question()
    {
        $data['game_question']  =   M('star_question')->order('star_question_id desc')->select();
        $this->assign("data",$data);
        $this->display('game_question');
    }

    public function game_question_add()
    {
        if (IS_AJAX) 
        {
            $data['answer']     =   I('post.answer','','htmlspecialchars');
            $data['category']   =   I('post.category','','htmlspecialchars');
            $data['imgsrc']     =   I('post.imgsrc','','htmlspecialchars');
            $data['sort']       =   I('post.sort','','htmlspecialchars');
            $data['puzzle1']    =   I('post.puzzle1','','htmlspecialchars');
            $data['puzzle2']    =   I('post.puzzle2','','htmlspecialchars');
            $data['puzzle3']    =   I('post.puzzle3','','htmlspecialchars');

            $result     =   M('star_question')->data($data)->add(); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '添加成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '添加失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $this->display('game_question_add');
        }
    }

    public function game_question_edit()
    {
        if (IS_AJAX) 
        {
            $where['star_question_id']  =   I('post.star_question_id','','htmlspecialchars');
            if (empty($where['star_question_id'])) 
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');    
            }

            $data['answer']     =   I('post.answer','','htmlspecialchars');
            $data['category']   =   I('post.category','','htmlspecialchars');
            $data['imgsrc']     =   I('post.imgsrc','','htmlspecialchars');
            $data['sort']       =   I('post.sort','','htmlspecialchars');
            $data['puzzle1']    =   I('post.puzzle1','','htmlspecialchars');
            $data['puzzle2']    =   I('post.puzzle2','','htmlspecialchars');
            $data['puzzle3']    =   I('post.puzzle3','','htmlspecialchars');

            $result     =   M('star_question')->where($where)->save($data); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '更新成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '更新失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $where['star_question_id']  =   I('get.id','','htmlspecialchars');

            if (empty($where['star_question_id'])) 
            {
                $this->error('非法请求');
            }

            $data['game_question']  =   M('star_question')->where($where)->find();

            if ( empty($data)) 
            {
                $this->error('数据不存在');
            }

            $this->assign("data",$data);
            $this->display('game_question_edit');
        }
    }

    //分享微信群
    public function wechat_group()
    {
        $data['wechat_group']  =   M('star_wechat_group')->order('star_wechat_group_id desc')->select();
        $this->assign("data",$data);
        $this->display('wechat_group');
    }

    //周排名mj_star_week
    public function week_ranking()
    {
        $order_by['star_week_id']   =   'desc';
        $order_by['getnum']         =   'desc';
        $data['star_week']  =   M('star_week')->order($order_by)->select();
        $this->assign("data",$data);
        $this->display('week_ranking');
    }


}